import random
import time

import requests
import json


def ddsVehicle():
    # url = "http://10.184.44.102:7200/dds-open-api/radar/find/vehicle"
    url = "http://dds.uat.immotors.com/dds-gateway/dds-open-api/radar/find/vehicle"
    payload = json.dumps({
        "latitude": "31.179251",
        "longitude": "121.618715",
        "distance": "100000000",
        "superId": "9300000000005586"
    })
    headers = {
        'Content-Type': 'application/json'
    }
    response = requests.request("POST", url, headers=headers, data=payload)
    return response.json()


def queryRoleRes(vin):
    url = "http://umc-sit.immotors.com/umc-relation/v3/vrs/queryRoleRes"
    # url = "http://api-uat.immotors.com/umc-relation/v3/vrs/queryRoleRes"
    payload = json.dumps({
        "relationParams": [
            {
                "role": "Owner",
                "vin": vin
            }
        ]
    })
    headers = {
        'Content-Type': 'application/json'
    }
    response = requests.request("POST", url, headers=headers, data=payload)
    return response.json()


def queryList(sid):
    url = "http://umc-sit.immotors.com/umc-relation/v3/vrs/preRelations"
    payload = json.dumps({
        "relationParams": [
            {
                "superId": sid
            }
        ]
    })
    headers = {
        'Content-Type': 'application/json',
        'Cookie': 'JSESSIONID=14872C46E2571FD371E72959FBA0F309'
    }
    response = requests.request("POST", url, headers=headers, data=payload)
    return response.json()


def queryUserInfo(vin_list):
    # url = "http://vass-sit.immotors.com/vass-api/user/queryUserInfoByVins"
    url = "http://vass-uat.immotors.com/vass-api/user/queryUserInfoByVins"
    payload = json.dumps({
        "vinList": vin_list
    })
    headers = {
        'Content-Type': 'application/json'
    }
    response = requests.request("POST", url, headers=headers, data=payload)
    return response.json()


def queryEngineeringVehicle(vin_list):
    # url = "http://vass-sit.immotors.com/vass-api/say-hi/query-engineering-vehicle"
    url = "http://vass-uat.immotors.com/vass-api/say-hi/query-engineering-vehicle"
    payload = json.dumps({
        "vinSet": vin_list
    })
    headers = {
        'Content-Type': 'application/json'
    }
    response = requests.request("POST", url, headers=headers, data=payload)
    return response.json()


data_list = ddsVehicle()["data"]
res_data = []
# vin_list = [each.get("vin") for each in data_list]
# random_data = random.sample(vin_list, 10)
# print(random_data)
for each in data_list:
    res_data.append(each.get("vin"))
print(res_data[:])

# my_data = queryEngineeringVehicle(res_data)
# print(my_data)
# my_data = queryUserInfo(res_data)
# data_list = my_data["data"]
# print(len(data_list))609XMS998391', 'LSJE36093MS998359']
# for item in data_list:
#     print(item)
